package cn.pdx.elec.container;

import org.apache.commons.lang.StringUtils;

/**
 * @Name:getService
 * @Description:返回服务节点
 * @author 彭定旭
 * @version：v1.00（版本号）
 * @Create Date:2013-3-25(创建日期)
 * @parameters:String serviceName(服务节点名称]
 * @return:object（接口）
 */
public class ServiceProvider {
  
	public static ServiceProviderCord serviceProviderCord;
	
	//加载applicationContext.xml文件
	static{
		
		System.out.println("先调用ServiceProvider方法加载applicationContext.xml");
		serviceProviderCord=new ServiceProviderCord();
		
		serviceProviderCord.load("applicationContext.xml");
	}
	
	public static Object getService(String serviceName)
	{  
		System.out.println("然后获取服务名称"+serviceName);
		//判断serviceName为不为空
		if(StringUtils.isBlank(serviceName))
		{
			throw new RuntimeException("当前服务名称不存在");
		}
		Object object=new Object();
		if(serviceProviderCord.applicationContext.containsBean(serviceName))
		{
			object=serviceProviderCord.applicationContext.getBean(serviceName);
		}
		if(object==null)
		{
			throw new RuntimeException("当前服务名称【"+serviceName+"】下的服务节点不存在");
		}
		return object;
	}
}
